package com.globant.fragment;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.globant.adapter.PlaceAdapter;
import com.globant.dao.PlaceDao;
import com.globant.domain.PlaceBean;
import com.globant.placemaps.R;

public class PlacesFragment extends ListFragment {
	
	private ListView placeList;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View map = inflater.inflate(R.layout.place_list, container, false);
		placeList = (ListView) map.findViewById(android.R.id.list);
		PlaceAdapter.placesFragment = this.getActivity();
		obtainList();
		return map;
	}

	public void obtainList() {
		PlaceDao placeDao = new PlaceDao(getActivity().getApplication());
		
		List<PlaceBean> places = placeDao.obtainResults();
		
		if (places != null && !places.isEmpty()) {
			PlaceAdapter adaptador = new PlaceAdapter(places);
			placeList.setAdapter(adaptador);
		}
	}


}
